//
//  InstitutionalAppointmentTableViewCell.swift
//  Venus
//
//  Created by point on 2018/10/9.
//  Copyright © 2018年 zhaowang. All rights reserved.
//

import UIKit

protocol InstitutionalAppointmentTableViewCellDelegate:class {
    func clickInstitutionalAppointmentTableViewCellBtn(cell:InstitutionalAppointmentTableViewCell , index:Int)
}

class InstitutionalAppointmentTableViewCell: UITableViewCell {
    
    fileprivate lazy var headImgView:UIImageView = UIImageView()
    fileprivate lazy var nameLabel:UILabel = UILabel()
    fileprivate lazy var timeLabel:UILabel = UILabel(kColorTextPlacehold, 10, "dddd")
    fileprivate lazy var telBtn:UIButton = UIButton()
    fileprivate lazy var remarkBtn:UIButton = UIButton()
    fileprivate lazy var lineView:UIView = UIView()
    
    weak var delegate:InstitutionalAppointmentTableViewCellDelegate?
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func clickPhoneBtn() {
        delegate?.clickInstitutionalAppointmentTableViewCellBtn(cell: self, index: 0)
    }
    
    @objc func clickRemarkBtn() {
        delegate?.clickInstitutionalAppointmentTableViewCellBtn(cell: self, index: 1)
    }
}

extension InstitutionalAppointmentTableViewCell {
    func configModel(model:InstitutionAppointModel , index:IndexPath) {
        nameLabel.text = model.userName
        timeLabel.text = String.stringToTimeStamp(stringTime: model.appointmentTime)
        headImgView.showImageI(model.headImg)
    }
}

extension InstitutionalAppointmentTableViewCell {
    func setupUI() {
        selectionStyle = .none
        contentView.addSubview(headImgView)
        contentView.addSubview(lineView)
        contentView.addSubview(nameLabel)
        contentView.addSubview(timeLabel)
        contentView.addSubview(remarkBtn)
        contentView.addSubview(telBtn)
        
        headImgView.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 50, height: 50))
            make.left.equalToSuperview().offset(20)
            make.centerY.equalToSuperview()
        }
        headImgView.image = UIImage(named: "bespeak_user")
        headImgView.fastCornerRadius(value: 25)
        
        nameLabel.font = UIFont.systemFont(ofSize: 14)
        nameLabel.textColor = kColorC5
        nameLabel.text = "ddd"
        nameLabel.snp.makeConstraints { (make) in
            make.left.equalTo(headImgView.snp.right).offset(10)
            make.centerY.equalTo(headImgView).offset(-10)
        }
        
        timeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(headImgView.snp.right).offset(13)
            make.centerY.equalTo(headImgView).offset(10)
        }
        
        remarkBtn.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 30, height: 30))
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().inset(22)
        }
        remarkBtn.setImage(UIImage.init(named: "bespeak_record"), for: .normal)
        
        
        telBtn.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 30, height: 30))
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().inset(75)
        }
        telBtn.setImage(UIImage.init(named: "bespeak_phone"), for: .normal)
        remarkBtn.addTarget(self, action: #selector(clickPhoneBtn), for: .touchUpInside)
        telBtn.addTarget(self, action: #selector(clickRemarkBtn), for: .touchUpInside)
        
        lineView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(0.5)
        }
        lineView.backgroundColor = nC1
        
    }
}
